{include file="common/header"}
<div id="app" v-cloak>
    <el-curd 
        ref="curd"
        :field="field" 
        :batch="[{title: '账号状态', field: ['status']}]"
        :table-sort="{prop: 'create_time', order: 'desc'}"
        :search-status="[{label: '正常', value: 1}, {label: '屏蔽', value: 0}]"
        search-keyword="请输入邮箱/账号/昵称/ID搜索"
        save-title="新增管理员">
        <template v-slot:dropdown="row">
            <li 
                v-if="!row.disabled && authority.indexOf(setPasswordUrl) !== -1"
                @click="openData(row, ['password'], '修改密码', setPasswordUrl)">
                修改密码
            </li>
            <li 
                v-if="!row.disabled && authority.indexOf(setGroupUrl) !== -1"
                @click="openData(row, ['group_id'], '更换角色', setGroupUrl)">
                更换角色
            </li>
            <li 
                v-if="!row.disabled && authority.indexOf(setStatusUrl) !== -1"
                @click="openData(row, ['status'], '状态账号', setStatusUrl)">
                账号状态
            </li>
        </template>
    </el-curd>
</div>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                setPasswordUrl:  'admin/password',
                setGroupUrl: 'admin/group',
                setStatusUrl: 'admin/status',
                authority: authority,
                field: [
                    {
                        label: '编号', 
                        prop: 'id',
                        table: false,
                    },
                    {
                        prop: 'cover', 
                        label: '管理员头像', 
                        table: {
                            label: '', 
                            is: 'el-image',
                            width: '60px',
                        },
                        form: {
                            is: 'el-file-upload',
                            type: '.png,.jpg,.jpeg',
                        },
                    },
                    {
                        prop: 'account', 
                        label: '管理员账号', 
                        table: {
                            label: '资料信息',
                            bind: ['email'],
                            sort: true
                        },
                        form: {
                            rules: [
                                {required: true, message: '不能为空'},
                                {pattern: /^[^\u4e00-\u9fa5]+$/, message: '不能包含中文字符'}
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'email', 
                        label: '管理员邮箱', 
                        table: false,
                        form: {
                            rules: [
                                {required: true, message: '不能为空'},
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'nickname', 
                        label: '管理员昵称', 
                        table: false,
                        form: {
                            rules: [
                                {required: true, message: '不能为空'},
                            ],
                        },
                    },
                    {
                        prop: 'login_count', 
                        label: '登录次数', 
                        table:{sort: true},
                        form: false,
                    },
                    {
                        prop: 'group_id', 
                        label: '所属角色',
                        table: {sort: true},
                        form: {
                            is: 'el-select', 
                            child: {
                                value: {:json_encode($group)}, 
                                props:{label: 'title', value: 'id'}
                            },
                            rules: [
                                {required: true, message: '不能为空'},
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'password', 
                        label: '登录密码', 
                        table: false, 
                        form: {
                            type: 'password',
                            placeholder: '不能包含中文字符',
                            rules: [
                                {required: true, message: '新增管理员时，密码不能为空'},
                                {pattern: /^[^\u4e00-\u9fa5]+$/, message: '不能包含中文字符'}
                            ],
                            update: false,
                        },
                    },
                    {
                        prop: 'create_time', 
                        label: '注册时间', 
                        table:{label: '注册&登录时间',sort: true, bind: ['login_time']},
                        form: false,
                    },
                    {
                        prop: 'status',
                        label: '当前状态',  
                        table: {sort: true}, 
                        form: {
                            is: 'el-switch',
                            default: 1,
                            update: false,
                        },
                    },
                ],
            }
        },
        methods: {
            // 打开数据
            openData(row, appoint, title, drawerSave) {
                this.$refs.curd.openData(row, appoint, title, drawerSave);
            },
        }
    })
</script>
{include file="common/footer"}